<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/2/7
 * Time: 17:12
 */
namespace App\Task;
use App\Service\MchAccountAccessService;
use App\Utils\CustomUtils;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Task\Annotation\Task;
use Hyperf\Utils\Coroutine;

/**
 * Class MchAccountAccessTask
 * @package App\Task
 * 消费者
 */
class MchAccountAccessTask
{

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * @Inject()
     * @var MchAccountAccessService
     */
    private $MchAccountAccessService;

    public function __construct(LoggerFactory $loggerFactory)
    {
        // 第一个参数对应日志的 name, 第二个参数对应 config/autoload/logger.php 内的 key
        $this->logger = $loggerFactory->get('log', 'default');
    }

    /**
     * @Task
     * @param $param 传递的数据是serialize序列化后的
     * @return array
     */
    public function handle($param)
    {
        $this->logger->info("MchAccountAccessTask handle");
        CustomUtils::xzxDebug(Coroutine::id());
        CustomUtils::xzxDebug($param);
        $param = unserialize($param);
        if (!isset($param['mchAccountId']) || empty($param['mchAccountId'])) {
            CustomUtils::xzxDebug("mchAccountId 缺失");
            return [];
        }
        if (!isset($param['accessType']) || empty($param['accessType'])) {
            CustomUtils::xzxDebug("accessType 缺失");
            return [];
        }
        CustomUtils::xzxDebug($param);
        $result = $this->MchAccountAccessService->handle($param);
        CustomUtils::xzxDebug($result);
        return [];
    }
}